import request from "@/utils/request";

const ExamAPI = {
  /**
   * 试卷
   */
  //试卷列表
  getExam(params: PageParams) {
    return request<any, PageResponse>({
      url: "/api/admin/exam/paper/page",
      method: "post",
      data: params,
    });
  },

  //学科列表
  getSubject() {
    return request<any, SubjectResponse[]>({
      url: "/api/admin/education/subject/list",
      method: "post",
    });
  },

  //删除功能
  delExam(id: string | number) {
    return request<any, null>({
      url: `/api/admin/exam/paper/delete/${id}`,
      method: "post",
    });
  },

  //编辑试卷
  editExam(params: PaperParams) {
    return request({
      url: "/api/admin/exam/paper/edit",
      method: "post",
      data: params,
    });
  },

  //根据id查询试卷
  searchPaperById(id: string | number) {
    return request<any, PaperParams>({
      url: `/api/admin/exam/paper/select/${id}`,
      method: "post",
    });
  },

  /**
   * 题目
   */
  //题目分页
  getQuestion(params: QuestionParams) {
    return request<any, QuestionResponse>({
      url: "/api/admin/question/page",
      method: "post",
      data: params,
    });
  },

  //单选题编辑
  questionAdd(params: QuestionAddType) {
    return request({
      url: "/api/admin/question/edit",
      method: "post",
      data: params,
    });
  },

  //删除题目
  delQuestion(id: string | number) {
    return request({
      url: `/api/admin/question/delete/${id}`,
      method: "post",
    });
  },

  //根据id查询题目
  searchQuestionById(id: string | number) {
    return request<any, QuestionAddType>({
      url: "/api/admin/question/select/" + id,
      method: "post",
    });
  },
};

export default ExamAPI;

export interface PageParams {
  id: null | string;
  level: null | string;
  subjectId: null | number | string; // 学科，允许为null、数字或字符串类型
  pageIndex: number; // 页码，默认为1
  pageSize: number; // 每页数量，默认为10
}

export interface PageResponse {
  total: number;
  list: Array<{
    id: string | number;
    name: string;
    questionCount: string | number;
    score: number;
    createTime: string;
    createUser: number | string;
    subjectId: string | number;
    paperType: string | number;
    frameTextContentId: string | number;
  }>;
}

//学科列表返回数据
export interface SubjectResponse {
  id: string | number;
  name: string; //学科名称
  level: string | number; //年级
  levelName: string; //年级名称
  itemOrder: null;
  deleted: boolean;
}

//题目列表返回数据
// 题目列表项类型
export interface QuestionItem {
  id: number | string;
  questionType: number | string; // 题型
  textContentId: null | number | string;
  createTime: string; // 时间格式
  subjectId: number | string; // 学科
  createUser: number | string; // 创建人
  score: number | string; // 得分
  status: number | string; // 状态
  correct: string; // 标答
  analyzeTextContentId: null | number | string;
  difficult: number | string; // 难度
  shortTitle: string; // 题干
}

// 题目列表响应类型
export interface QuestionResponse {
  total: number; // 总数
  list: QuestionItem[]; // 题目列表数组
}

//题目列表请求参数
export interface QuestionParams {
  id: null | number | string;
  questionType: null | number | string;
  level: null | number | string;
  subjectId: null | number | string;
  pageIndex: number;
  pageSize: number;
}

//新增题目
export interface QuestionAddType {
  id: null | number;
  questionType: number;
  subjectId: null | number;
  title: string;
  gradeLevel: null | number;
  items: AnswerType[];
  analyze: string;
  correctArray: (string | number)[];
  correct: string;
  score: number;
  difficult: number;
}

export interface AnswerType {
  prefix: string;
  content: string;
  score?: number;
  id?: number | string | null;
  itemUuid?: string;
}

//试卷编辑输入参数
export interface PaperParams {
  id: string | number | null; //试卷id
  level: string | number | null; //年级
  subjectId: string | number | null; //学科
  paperType: string | number | null; //试卷类型
  name: string; //试卷名称
  suggestTime: string | number; //考试时长
  limitDateTime: string[]; //限时
  titleItems: TitleItems[];
  score: string | number; //试卷总分
}
export interface TitleItems {
  name: string; //标题
  questionItems: QuestionAddType[];
}
